package com.yl.ydk.view;

import android.content.Context;
import android.util.AttributeSet;
import android.view.View;

import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import androidx.viewpager.widget.ViewPager;

import com.yl.ydk.base.BaseFragmentPageAdapter;

public class myViewPager extends ViewPager {
    public myViewPager(@NonNull Context context) {
        super(context);
    }

    public myViewPager(@NonNull Context context, @Nullable AttributeSet attrs) {
        super(context, attrs);
    }

    @Override
    protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
        int height = 0;
        BaseFragmentPageAdapter vpFragmentAdapter = (BaseFragmentPageAdapter) getAdapter();
        if (vpFragmentAdapter != null) {
            View child = vpFragmentAdapter.getItem(getCurrentItem()).getView();
            if (child != null) {
//                LogUtil.e("viewpager="+getCurrentItem());
                child.measure(widthMeasureSpec, MeasureSpec.makeMeasureSpec(0, MeasureSpec.UNSPECIFIED));
                height = child.getMeasuredHeight();
            }
        }
        heightMeasureSpec = MeasureSpec.makeMeasureSpec(height, MeasureSpec.EXACTLY);
        super.onMeasure(widthMeasureSpec, heightMeasureSpec);
    }

}